package com.spring.mvc.controller;

import com.spring.mvc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @version 1.0.0
 * @Date: 2022/6/15 20:59
 * @Author ZhuYouBin
 * @Description
 */
@Controller
public class ParamController {

    // 请求参数和方法参数自动映射
    @RequestMapping("/param01")
    public String param01(String username, String password) {
        System.out.println("username=" + username);
        System.out.println("password=" + password);
        return "hello";
    }

    // HttpServletRequest获取参数
    @RequestMapping("/param02")
    public String param02(HttpServletRequest request) {
        System.out.println("username=" + request.getParameter("username"));
        System.out.println("password=" + request.getParameter("password"));
        return "hello";
    }

    // HttpServletRequest获取参数
    @RequestMapping("/param03")
    public String param03(@RequestParam("uname") String username, @RequestParam("pass") String password) {
        System.out.println("username=" + username);
        System.out.println("password=" + password);
        return "hello";
    }

    // HttpServletRequest获取参数
    @RequestMapping("/param04")
    public String param04(User user) {
        System.out.println("username=" + user.getUsername());
        System.out.println("password=" + user.getPassword());
        return "hello";
    }

    // HttpServletRequest获取参数
    @RequestMapping("/param05/{username}/{password}")
    public String param05(@PathVariable String username, @PathVariable String password) {
        System.out.println("username=" + username);
        System.out.println("password=" + password);
        return "hello";
    }

    // HttpServletRequest获取参数
    @RequestMapping("/param06/{uname}/{pass}")
    public String param06(@PathVariable("uname") String username, @PathVariable("pass") String password) {
        System.out.println("username=" + username);
        System.out.println("password=" + password);
        return "hello";
    }

}
